package com.epfly.base.ex;

import org.apache.commons.lang3.exception.ExceptionUtils;

public class PromoException extends RuntimeException {

    private int errCode;

    private String errMsg;

    private String errorDetail;


    public PromoException(int errCode, String errMsg) {
        super(errMsg);
        this.errCode = errCode;
        this.errMsg = getMessage();
    }

    public PromoException(int errCode, String errMsg, Throwable e) {
        super(errMsg, e);
        this.errCode = errCode;
        this.errMsg = getMessage();
        this.errorDetail = ExceptionUtils.getStackTrace(e);
    }

    /**
     * args可以是格式化入参，也可以是errMessage，此 messageEnum 的 errMsg 属性为 %s
     */
    public PromoException(PromoMessageEnum messageEnum, Object... args) {
        super(String.format(messageEnum.getErrMsg(), args));
        this.errCode = messageEnum.getErrCode();
        this.errMsg = getMessage();
    }

    public PromoException(PromoMessageEnum messageEnum, Throwable e, Object... args) {
        super(String.format(messageEnum.getErrMsg(), args), e);
        this.errCode = messageEnum.getErrCode();
        this.errMsg = getMessage();
        this.errorDetail = ExceptionUtils.getStackTrace(e);
    }


    public int getErrCode() {
        return errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }


}
